// app.js
<script>
	import config from './config'
	import bluetoothService from '@/utils/bluetoothService.js'
	import {
		getToken
	} from '@/utils/auth'

	export default {
		onLaunch: function() {
			console.log('App Launch')
			this.initApp()
			
			// 初始化蓝牙服务
			bluetoothService.init()
			
			// 检查并恢复蓝牙连接
			setTimeout(() => {
				bluetoothService.checkConnection()
			}, 1000)
		},
		
		onShow: function() {
			console.log('App Show')
			// App回到前台时检查连接
			bluetoothService.checkConnection()
		},
		
		onHide: function() {
			console.log('App Hide')
			// App进入后台时，蓝牙连接会自动保持
		},
	
		methods: {
			// 初始化应用
			initApp() {
				// 初始化应用配置
				this.initConfig()
				// 检查用户登录状态
				this.checkLogin()
			},
			
			initConfig() {
				this.globalData.config = config
			},
			
			checkLogin() {
				if (!getToken()) {
					this.$tab.reLaunch('/pages/login')
				}
			}
		}
	}
</script>

<style lang="scss">
	@import '@/static/scss/index.scss'
</style>